define(['module', 'react', '../BaseDemo', 'classnames', 'Input', 'InputNumber', 'CheckBoxGroup', 'RadioGroup', 'DateTime', 'Select', 'TextArea', 'Upload', "../Tile", 'Label', 'FormControl', 'Form', 'Card', 'Table', 'Button', 'business/SimpleForm'], function (module, React, BaseDemo, classnames, Input, InputNumber, CheckBoxGroup, RadioGroup, DateTime, Select, TextArea, Upload, Tile, Label, FormControl, Form, Card, Table, Button, SimpleForm) {
    'use strict';

    var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
        return typeof obj;
    } : function (obj) {
        return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
    };

    var _extends = Object.assign || function (target) {
        for (var i = 1; i < arguments.length; i++) {
            var source = arguments[i];

            for (var key in source) {
                if (Object.prototype.hasOwnProperty.call(source, key)) {
                    target[key] = source[key];
                }
            }
        }

        return target;
    };

    function _classCallCheck(instance, Constructor) {
        if (!(instance instanceof Constructor)) {
            throw new TypeError("Cannot call a class as a function");
        }
    }

    var _createClass = function () {
        function defineProperties(target, props) {
            for (var i = 0; i < props.length; i++) {
                var descriptor = props[i];
                descriptor.enumerable = descriptor.enumerable || false;
                descriptor.configurable = true;
                if ("value" in descriptor) descriptor.writable = true;
                Object.defineProperty(target, descriptor.key, descriptor);
            }
        }

        return function (Constructor, protoProps, staticProps) {
            if (protoProps) defineProperties(Constructor.prototype, protoProps);
            if (staticProps) defineProperties(Constructor, staticProps);
            return Constructor;
        };
    }();

    function _possibleConstructorReturn(self, call) {
        if (!self) {
            throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
        }

        return call && (typeof call === "object" || typeof call === "function") ? call : self;
    }

    function _inherits(subClass, superClass) {
        if (typeof superClass !== "function" && superClass !== null) {
            throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
        }

        subClass.prototype = Object.create(superClass && superClass.prototype, {
            constructor: {
                value: subClass,
                enumerable: false,
                writable: true,
                configurable: true
            }
        });
        if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
    }

    var InputPage = function (_BaseDemo) {
        _inherits(InputPage, _BaseDemo);

        function InputPage(props) {
            _classCallCheck(this, InputPage);

            var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(InputPage).call(this, props));

            _this.state = {
                data: []
            };

            _this.rowIndex = 0;
            return _this;
        }

        _createClass(InputPage, [{
            key: 'renderByConfig',
            value: function renderByConfig() {
                var formData = {
                    action: "asdasdasd",
                    method: "post",
                    props: {
                        layout: "stack-inline",
                        labelWidth: "120",
                        useDefaultSubmitBtn: true,
                        submitText: "",
                        target: "",
                        className: "",
                        style: {}
                    },
                    items: [{ name: "shortName", label: "企业简称：", type: "text", props: {}, rules: { required: true }, messages: {} }, { name: "name", label: "企业名称：", type: "text", props: {}, rules: {}, messages: {} }, { name: "email", label: "企业联系邮箱：", type: "text", props: {}, rules: {}, messages: {} }, { name: "tel", label: "企业联系电话：", type: "text", props: {}, rules: {}, messages: {} }, { type: "row", props: { className: "cm-form-inline" }, children: [{ name: "province", label: "详细地址：", type: "select", props: {
                                data: [{ id: "0", text: "北京" }, { id: "1", text: "上海" }]
                            }, rules: {}, messages: {} }, { name: "city", label: "", type: "select", props: {
                                data: [{ id: "0", text: "海淀" }, { id: "1", text: "浦东" }]
                            }, rules: {}, messages: {} }] }, { name: "address", label: "&nbsp;", type: "textarea", props: {
                            itemStyle: { height: 150 }
                        }, rules: {}, messages: {} }]
                };

                var formProps = _extends({}, formData.props || {});
                this.mergeProps(formProps, formData, ["action", "method", "encType"]);

                this.keyIndex = 0;

                return React.createElement(
                    Form,
                    formProps,
                    this.renderItems(formData.items)
                );
            }
        }, {
            key: 'renderItems',
            value: function renderItems(items) {
                var _this2 = this;

                if (items) {
                    return items.map(function (item) {
                        if (item.type !== "row") {
                            var itemProps = _extends({}, item.props || {});
                            _this2.mergeProps(itemProps, item, ["name", "type", "rules", "messages"]);
                            itemProps.key = _this2.keyIndex++;
                            return React.createElement(FormControl, _extends({}, itemProps, { label: item.label, onChange: function onChange(value) {
                                    item.value = value;
                                } }));
                        } else {
                            return _this2.renderFormRow(item);
                        }
                    });
                }
                return null;
            }
        }, {
            key: 'renderFormRow',
            value: function renderFormRow(item) {
                var items = this.renderItems(item.children);
                return React.createElement(
                    Form.Row,
                    _extends({}, item.props, { key: this.keyIndex++ }),
                    items
                );
            }
        }, {
            key: 'renderTableForm',
            value: function renderTableForm() {
                var _this3 = this;

                if (this.state.data) {
                    return this.state.data.map(function (item) {
                        var tds = item.cells.map(function (child, index) {
                            var itemProps = _extends({}, child.props || {});
                            _this3.mergeProps(itemProps, child, ["value", "name", "type", "rules", "messages"]);
                            return React.createElement(
                                'td',
                                { key: index },
                                React.createElement(FormControl, _extends({}, itemProps, { label: item.label }))
                            );
                        });
                        return React.createElement(
                            'tr',
                            { key: item.key, 'data-index': item.key },
                            tds
                        );
                    });
                }
                return null;
            }
        }, {
            key: 'addRow',
            value: function addRow() {
                var data = this.state.data;

                this.rowIndex++;
                // data.push(
                //     {
                //         key: "tableRow"+this.rowIndex,
                //         data: [
                //             <FormControl name="entName" value="111" rules={{required: true}}/>,
                //             <FormControl name="loopDomain" type="textarea" rules={{required: true}}/>,
                //             <FormControl name="url" type="textarea" rules={{required: true}}/>,
                //             <FormControl name="clientIP" type="select" rules={{required: true}} data={[{id: "0", text: "北京"},{id: "1", text: "上海"}]}/>,
                //             <FormControl name="district" type="select" rules={{required: true}} data={[{id: "0", text: "北京"},{id: "1", text: "上海"}]}/>
                //         ]
                //     }
                // );
                this.refs.table.addRow({
                    id: "tableRow" + this.rowIndex,
                    domain: React.createElement(FormControl, { name: 'domain', type: 'text', value: 'www.baidu.com' }),
                    loopDomain: React.createElement(FormControl, { name: 'loopDomain', type: 'textarea' }),
                    url: React.createElement(FormControl, { name: 'url', type: 'textarea' }),
                    clientIP: React.createElement(FormControl, { name: 'clientIP', type: 'select', data: [{ id: "0", text: "北京" }, { id: "1", text: "上海" }] }),
                    district: React.createElement(FormControl, { name: 'district', type: 'select', data: [{ id: "0", text: "北京" }, { id: "1", text: "上海" }] })
                });
            }
        }, {
            key: 'removeRow',
            value: function removeRow() {
                var data = this.refs.table.getData();
                data.splice(0, 1);
                this.setState({ data: data });
            }
        }, {
            key: 'getTableFormData',
            value: function getTableFormData() {
                var data = this.refs.table.getData();
                if (data) {
                    var params = data.map(function (item) {
                        var itemData = item.data;
                        var param = {};
                        for (var keyName in itemData) {
                            if (_typeof(itemData[keyName]) == 'object' && React.isValidElement(itemData[keyName])) {
                                param[keyName] = itemData[keyName].getValue();
                            }
                        }

                        return param;
                    });

                    console.log(params);
                }
            }
        }, {
            key: 'mergeProps',
            value: function mergeProps(target, source, props) {
                if (props) {
                    props.forEach(function (prop) {
                        if (source[prop] != undefined) {
                            target[prop] = source[prop];
                        }
                    });
                }
            }
        }, {
            key: 'render',
            value: function render() {

                var groupData = [{ id: "0", text: "iPhone" }, { id: "1", text: "Android" }, { id: "2", text: "WinPhone" }];

                return React.createElement(
                    'div',
                    { className: 'container' },
                    React.createElement(
                        Tile,
                        { header: "基本使用" },
                        React.createElement(
                            Card,
                            { title: '1' },
                            React.createElement(SimpleForm, { data: {
                                    "method": "get",
                                    "action": "",
                                    "layout": "stack-inline",
                                    "labelWidth": 100,
                                    "items": [{
                                        "name": "row",
                                        "type": "row",
                                        "children": [{
                                            "name": "inputnumber",
                                            "type": "inputnumber",
                                            "label": "阿萨德"
                                        }, {
                                            "name": "label",
                                            "type": "label",
                                            "label": "Undefined"
                                        }],
                                        "className": "cm-form-inline"
                                    }, {
                                        "name": "row",
                                        "type": "row",
                                        "children": [{
                                            "name": "input",
                                            "type": "input",
                                            "label": "file"
                                        }, {
                                            "name": "button",
                                            "type": "button",
                                            "label": "liulan..."
                                        }],
                                        "className": "cm-form-inline"
                                    }]
                                } })
                        ),
                        React.createElement(
                            Card,
                            { title: '企业基本信息' },
                            this.renderByConfig()
                        ),
                        React.createElement(
                            Card,
                            { title: '域名配置' },
                            React.createElement(
                                Button,
                                { onClick: this.addRow.bind(this) },
                                '添 加'
                            ),
                            React.createElement(
                                Button,
                                { onClick: this.removeRow.bind(this) },
                                '删 除'
                            ),
                            React.createElement(
                                Button,
                                { onClick: this.getTableFormData.bind(this) },
                                '获取数据'
                            ),
                            React.createElement(Table, { ref: 'table', data: [], columns: [{ name: "domain", text: "域名" }, { name: "loopDomain", text: "回源IP/回源域名" }, { name: "url", text: "回源检测URL" }, { name: "clientIP", text: "获取客户端IP" }, { name: "district", text: "加速区域" }] })
                        ),
                        React.createElement(
                            Card,
                            { title: '企业基本信息' },
                            React.createElement(
                                Form,
                                { layout: "stack-inline", labelWidth: '120', tipAuto: true },
                                React.createElement(FormControl, { type: 'text', name: 'shortName', label: '企业简称：', placeholder: '企业简称', required: true, rules: { noSpecial: true, maxLength: 15, minLength: 6 } }),
                                React.createElement(FormControl, { type: 'text', name: 'name', label: '企业名称：', required: true, value: '111', readOnly: true }),
                                React.createElement(FormControl, { type: 'text', name: 'email', label: '企业联系邮箱：', required: true, rules: { email: true } }),
                                React.createElement(FormControl, { type: 'text', name: 'tel', label: '企业联系电话：', required: true, rules: { mobile: true }, maxLength: 11 }),
                                React.createElement(
                                    Form.Row,
                                    { className: 'cm-form-inline' },
                                    React.createElement(FormControl, { type: 'select', name: 'province', label: '详细地址：', required: true, data: [{ id: "0", text: "北京" }, { id: "1", text: "上海" }] }),
                                    React.createElement(FormControl, { type: 'select', name: 'city', required: true, data: [{ id: "0", text: "海淀" }, { id: "1", text: "浦东" }] })
                                ),
                                React.createElement(FormControl, { type: 'textarea', label: ' ', name: 'address', itemStyle: { height: 150 }, required: true }),
                                React.createElement(
                                    Form.Row,
                                    { className: 'cm-form-inline', style: { display: "none" } },
                                    React.createElement(FormControl, { type: 'text', name: 'hiddenE', label: '', required: true, rules: { email: true } })
                                )
                            )
                        ),
                        React.createElement(
                            Card,
                            { title: '企业基本信息' },
                            React.createElement(
                                Form,
                                { layout: "inline" },
                                React.createElement(FormControl, { type: 'text', name: 'name', label: '企业简称：', required: true, rules: { noSpecial: true, maxLength: 15, minLength: 6 } }),
                                React.createElement(FormControl, { type: 'text', name: 'age', label: '企业名称：', required: true }),
                                React.createElement(FormControl, { type: 'text', name: 'age', label: '企业联系邮箱：', required: true }),
                                React.createElement(FormControl, { type: 'text', name: 'age', label: '企业联系电话：', required: true })
                            )
                        )
                    ),
                    React.createElement(
                        Tile,
                        { header: "Ajax提交" },
                        React.createElement(
                            Form,
                            { action: 'xxxxx', layout: 'stack', method: 'ajax' },
                            React.createElement(FormControl, { type: 'text', name: 'name', label: '姓名', grid: 1, required: true, rules: { noSpecial: true, maxLength: 15, minLength: 6 } }),
                            React.createElement(FormControl, { type: 'number', name: 'age', label: '年龄', grid: 1, required: true }),
                            React.createElement(FormControl, { type: 'datetime', name: 'activeTime', label: '时间:', grid: 1, required: true }),
                            React.createElement(FormControl, { type: 'select', name: 'area', label: '区域:', required: true, data: [{ id: "0", text: "中国" }, { id: "1", text: "美国" }], grid: 1 }),
                            React.createElement(FormControl, { type: 'radio', name: 'type', label: '选择:', required: true, data: groupData }),
                            React.createElement(FormControl, { type: 'file', name: 'file', label: '选择:', grid: 1, required: true })
                        )
                    )
                );
            }
        }]);

        return InputPage;
    }(BaseDemo);

    module.exports = InputPage;
});
